package g2.routemaster.gui.actions;

import g2.routemaster.gui.ApplicationStart;
import g2.routemaster.gui.GManager;
import g2.routemaster.model.GameManager;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.window.ApplicationWindow;

public class StartGameAction extends Action {
   private ApplicationWindow window;
   public StartGameAction(ApplicationWindow window) {
      setText("Start Game");
      this.window = window;
   }
   
   public void run() {
      GameManager gm = GManager.instance().getGameManager();
      if(!gm.canStart()){
         MessageDialog.openError(
               window.getShell(), 
               "Error", 
               "Can't start game, because preconditions are not filled!"
               + System.getProperty("line.separator")
               + "Obviously there is less than 2 players on board.");
      } else if(gm.isGameStarted()) {
         MessageDialog.openError(
               window.getShell(), 
               "Error", 
               "Game has already started!");
      } else {
         gm.startGame();
         ((ApplicationStart)window).createGamingBoard();
      }
   }
}
